package com.etoak.car.service;


import com.etoak.car.bean.Car;
import com.etoak.car.bean.Order;
import com.etoak.car.bean.Types;
import com.etoak.car.mapper.CarMapper;
import com.etoak.commons.page.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarService {

    @Autowired
    private CarMapper dao;
    public Page<Car> querySome(int pageNum, int pageSize,String name) {
        PageHelper.startPage(pageNum,pageSize);
        //查询功能
        List<Car> cars = dao.queryList(name);
        //创建pageInfo
        PageInfo<Car> pageInfo = new PageInfo<>(cars);

        //返回结果
        return new Page<>(pageInfo.getPageNum(),
                pageInfo.getPageSize(),
                pageInfo.getTotal(),
                cars,
                pageInfo.getPages());

    }

    public List<Types> queryCarType() {
        return dao.queryCarType();
    }

    public int addCar(Car car) {
        return dao.addCar(car);
    }

    public int addType(String name, String status) {
        return dao.addType(name,status);
    }

    public int delType(int typeId) {
        return dao.delType(typeId);
    }

    public int updateType(int id, String name, String status) {
        return dao.updateType(id,name,status);
    }


    public Car queryCarById(String carId) {
        return dao.queryCarById(carId);
    }

    public int updateCar(Car car) {
        return dao.updateCar(car);
    }

    public int delCar(String id) {
        return dao.delCar(id);
    }
}
